package cn.vc.shop.controller;

import cn.vc.auth.entity.po.VUser;
import cn.vc.basicmodule.entity.Result;
import cn.vc.shop.entity.po.Shop;
import cn.vc.shop.service.ShopActService;
import cn.vc.shop.service.ShopService;
import cn.vc.shop.util.SecurityUtil;
import com.github.benmanes.caffeine.cache.Cache;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop_act")
public class ShopActController {
    private final ShopService shopService;
    private final ShopActService shopActService;
    private final RedisTemplate redisTemplate;
    private final Cache<String, Shop> shopCache;

    public ShopActController(ShopService shopService, ShopActService shopActService, RedisTemplate redisTemplate, Cache<String, Shop> shopCache) {
        this.shopService = shopService;
        this.shopActService = shopActService;
        this.redisTemplate = redisTemplate;
        this.shopCache = shopCache;
    }



    /**
     * <h2>关注社区</h2>
     * @param token
     * @param shopId
     * @return
     */
    @PostMapping("/1")
    public Result<?> follow(@RequestHeader(value = "token") String token,
                            @RequestParam("shopId") Long shopId) {
        VUser myUser = SecurityUtil.getUser();
        if (myUser==null) return Result.NOT_LOGGED_IN();
        int i = shopActService.follow(myUser.getId(), shopId);
        return new Result<>(i);
    }
    /**
     * <h2>社区评分</h2>
     * @param token
     * @param shopId
     * @param mark
     * @return
     */
    @PostMapping("/2")
    public Result<?> marking(@RequestHeader(value = "token") String token,
                             @RequestParam("shopId") Long shopId, @RequestParam("mark") Integer mark) {
        VUser myUser = SecurityUtil.getUser();
        if (myUser==null) return Result.NOT_LOGGED_IN();
        boolean bo = shopActService.marking(myUser.getId(), shopId, mark);
        return new Result<>(bo);
    }



    /**
     * <h2>取关社区</h2>
     * @param token
     * @param shopId
     * @return
     */
    @DeleteMapping("/1")
    public Result<?> noFollow(@RequestHeader(value = "token") String token,
                              @RequestParam("shopId") Long shopId) {
        VUser myUser = SecurityUtil.getUser();
        if (myUser==null) return Result.NOT_LOGGED_IN();
        int i = shopActService.noFollow(myUser.getId(), shopId);
        return new Result<>(i);
    }
}
